/**##########################################################################################**/
/**                                    路由工具类                                              **/
/**##########################################################################################**/
import { routes } from "@/router/router.ts";

/**
 *  根据绝对路径获取路由标题
 * @param path 路径
 */
function getTitleByAbsolutePath(path: string): string {
    let title = "";
    routes.forEach((route) => {
        if (route.children) {
            route.children.forEach((child) => {
                if (child.meta && child.meta.absolutePath === path) {
                    title = child.meta.title as string;
                }
            });
        }
    });
    return title;
}

/**
 * 根据标题获取绝对路径
 */
function getAbsolutePathByTitle(title: string): string {
    let absolutePath = "";
    routes.forEach((route) => {
        if (route.children) {
            route.children.forEach((child) => {
                if (child.meta && child.meta.title === title) {
                    absolutePath = child.meta.absolutePath as string;
                }
            });
        }
    });
    return absolutePath;
}

const RouterTool = {
    getTitleByAbsolutePath,
    getAbsolutePathByTitle,
};
export default RouterTool;